package Coller

import (
	"github.com/gin-gonic/gin"
	"math/rand"
	"net/http"
	"strconv"
	"week2/models"
	"week2/pkg"
)

func OrderAdd(c *gin.Context) {

	//o, _ := uuid.NewUUID()
	p := rand.Intn(9000) + 1000
	ShopId, _ := strconv.Atoi("shop_id")
	ShopName := c.PostForm("order_id")
	ShopPrice, _ := strconv.Atoi("shop_price")
	pone := models.Order{
		OrderId:   strconv.Itoa(p),
		ShopId:    ShopId,
		ShopName:  ShopName,
		ShopPrice: ShopPrice,
	}
	pkg.NewRabbitMQPubSub("Order_exchange")
	pkg.NewRabbitMQ(ShopName, "o", ShopName)
	err := pone.OrderAdd()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": -1,
			"msg":  "失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "成功",
	})
	return
}
